//
//  MediaImpressViewController.m
//  meiyinxiang
//  
//  Created by apple on 2017/10/17.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

#import "MediaImpressViewController.h"
#import "AppDelegate.h"
#import "MYXCusGuideController.h"
#import "KGModal.h"
#import "MyLocation.h"

//#import "CHSocialService.h"
#import "JpusharedHelper.h"
#import "ShareUrlModel.h"

#import "BMKClusterManager.h"
#import "NSObject+CZRuntime.h"
#import "LocationNowBtn.h"
#import "UIImage+Category.h"
#import "CustomerServiceBtn.h"
#import "RefreshBtn.h"
#import "NoticeView.h"
#import "QuestionBtn.h"

#import "MYXOpenLuckyMoneyView.h"
#import "MYXHpVocherView.h"
#import "MYXLuckyMoneyListViewModel.h"
#import "MXYLuckymoneyViewModel.h"
#import "MYXHomepageVocherVIewModel.h"

#define BtnCornerRadius 24
@interface ClusterAnotion:BMKPointAnnotation
//anotation个数
@property (nonatomic,assign) NSInteger size;
@property (nonatomic,strong) MXYLuckymoneyViewModel *model;

@end
@implementation ClusterAnotion

@synthesize size = _size;
@end
@interface VocherAnnotation:BMKPointAnnotation
//anotation个数
@property (nonatomic,assign) NSInteger size;
@property (nonatomic,strong) MYXHomepageVocherVIewModel *model;

@end
@implementation VocherAnnotation

@synthesize size = _size;
@end
//官方红包券
@interface OfficialVocherAnotion:BMKPointAnnotation
@end
@implementation OfficialVocherAnotion

@end
//点聚合AnotationView
@interface ClusterAnotionView : BMKPinAnnotationView
@property (nonatomic,assign) NSInteger size;
@property (nonatomic,strong) UILabel *label;
@end

@implementation ClusterAnotionView

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setBounds:CGRectMake(0.f, 0.f, 22.f, 22.f)];
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0.f, 0.f, 22.f, 22.f)];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:11];
        _label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_label];
        self.alpha = 0.85;
    }
    return self;
    
}
- (void)setSize:(NSInteger)size {
    _size = size;
    if (_size == 1) {
        self.label.hidden = YES;
        self.tintColor = BMKPinAnnotationColorRed;
        return;
    }
    self.label.hidden = NO;
    if (size > 20) {
        self.label.backgroundColor = [UIColor redColor];
    } else if (size > 10) {
        self.label.backgroundColor = [UIColor purpleColor];
    } else if (size > 5) {
        self.label.backgroundColor = [UIColor blueColor];
    } else {
        self.label.backgroundColor = [UIColor greenColor];
    }
    _label.text = [NSString stringWithFormat:@"%ld", size];
}

@end

@interface MediaImpressViewController ()
{
    BMKMapView *_mapView;
    BMKPointAnnotation* lockedScreenAnnotation;//锁屏点
    BMKLocationService *_locationService;//定位服务
    BMKCircle* circle;//经度圈

    LocationNowBtn *locationNowBtn;//定位到现在的位置btn
    CustomerServiceBtn *customerSeviceBtn;//客服电话
    RefreshBtn *refreshBtn;//刷新周围红包
    NoticeView *noticeView;//通知滚动视图
    QuestionBtn *questionBtn;//用户指南
    CLLocationCoordinate2D coor;//中心点经纬度
    MYXOpenLuckyMoneyView *openLuckyView;//红包界面
    
}
@property (nonatomic,strong) MYXLuckyMoneyListViewModel *moneyViewModel;
@property (nonatomic,strong) NSMutableArray *annotationArray;
@property (nonatomic,strong) BMKPointAnnotation *officailVocher;//第一次进入app，官方红包券

//首页定位
@property(nonatomic, strong) BMKLocationManager *locationManager;
@property(nonatomic, assign) BOOL isNeedAddr;
@property(nonatomic, assign) BOOL isNeedHotSpot;
@property(nonatomic, copy) BMKLocatingCompletionBlock completionBlock;

@end

@implementation MediaImpressViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self;
    _locationService.delegate = self;
    noticeView.noticeString = [MYXMemberMdel sharedInstance].notices;
    [noticeView addRollAction];
       // self.navigationController.navigationBar.hidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [_mapView viewWillDisappear];
    _mapView.delegate = nil;
    _locationService.delegate = nil;
    [noticeView leaveDispatch];
    //_mapView = nil;
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    if (self.moneyViewModel == nil) {
        self.moneyViewModel = [[MYXLuckyMoneyListViewModel alloc] init];
    }
    if (self.annotationArray == nil) {
        self.annotationArray = [NSMutableArray array];
    }
    [self configBaiduMap];
    [self createUI];
     [self addNotice];

}
- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    
    [_locationManager stopUpdatingLocation];
    _locationManager.delegate = nil;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -BaiduMapMethod
//添加锁定按钮
- (void)addLockedMapAnnotation{
    
    CGPoint centerPoint =_mapView.center;
    if (lockedScreenAnnotation == nil) {
        lockedScreenAnnotation = [[BMKPointAnnotation alloc] init];
        lockedScreenAnnotation.isLockedToScreen = YES;
        lockedScreenAnnotation.screenPointToLock = centerPoint;
    }
    CLLocationCoordinate2D locationcoor = [_mapView convertPoint:centerPoint toCoordinateFromView:_mapView];
    NSLog(@"location lon and late %f",locationcoor.longitude);
    // 添加一个PointAnnotation
    coor.latitude = locationcoor.latitude;
    coor.longitude = locationcoor.longitude;
    [self.moneyViewModel loadLuckyMoneysWith5kmWithlon:[NSString stringWithFormat:@"%f",coor.longitude] lite:[NSString stringWithFormat:@"%f",coor.latitude] Completion:^(BOOL success, NSString *message) {
        if (success) {
            [self.annotationArray removeAllObjects];
            //添加普通红包
            for (MXYLuckymoneyViewModel* model in self.moneyViewModel.viewModelList) {
                ClusterAnotion *annotation = [[ClusterAnotion alloc] init];
                annotation.coordinate  = CLLocationCoordinate2DMake( model.latitude, model.longitude);
                annotation.model = model;
                annotation.title = [NSString stringWithFormat:@"点我抢红包"];
                [self.annotationArray addObject:annotation];
            }
            //添加满减红包券
            for (MYXHomepageVocherVIewModel *vocherViewModel in self.moneyViewModel.vocherViewModelList) {
                VocherAnnotation *vocherAnotation = [[VocherAnnotation alloc] init];
                vocherAnotation.coordinate = CLLocationCoordinate2DMake( vocherViewModel.latitude, vocherViewModel.longitude);
                vocherAnotation.model = vocherViewModel;
                vocherAnotation.title = [NSString stringWithFormat:@"点我领红包抵用券"];
                [self.annotationArray addObject:vocherAnotation];
                
            }
            
            [_mapView removeAnnotations:_mapView.annotations];
            [_mapView addAnnotations:self.annotationArray];
            [_mapView addAnnotation:lockedScreenAnnotation];
            if (!self.moneyViewModel.isReceivedVocher) {//未领取红包体验卷
                self.officailVocher.title = @"媒印象给您红包了，点我领取";
                [_mapView addAnnotation:self.officailVocher];
            }
        }
    }];
    
}
#pragma mark - BMKMapViewDelegate

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
    //普通annotation
    if ([annotation isKindOfClass:[ClusterAnotion class]]) {
        NSString *AnnotationViewID = @"ClusterMark";
        ClusterAnotion *cluster = (ClusterAnotion*)annotation;
        BMKPinAnnotationView *annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:cluster reuseIdentifier:AnnotationViewID];
            annotationView.image = cluster.model.luckyMoneyImg;

        annotationView.draggable = YES;
        annotationView.annotation = cluster;

        return annotationView;
    }else if ([annotation isKindOfClass:[VocherAnnotation class]]){
        NSString *vocherViewId = @"vocherViewId";
        VocherAnnotation * vocherAnnotation= (VocherAnnotation *)annotation;
        BMKPinAnnotationView *annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:vocherAnnotation reuseIdentifier:vocherViewId];
        annotationView.image = vocherAnnotation.model.VocherImg;
        return annotationView;
    }else{
        NSString *normalAnnotationId = @"normalAnnotationId";
        BMKPinAnnotationView *normalAnnotaitonView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:normalAnnotationId];
        normalAnnotaitonView.pinColor = BMKPinAnnotationColorPurple;
        normalAnnotaitonView.animatesDrop = NO;// 设置该标注点动画显示
        if (annotation == _officailVocher) {
            normalAnnotaitonView.image = [UIImage imageNamed:@"meidia_test_vocher"];

        }else{
            normalAnnotaitonView.image = [UIImage imageNamed:@"media_annotionImage"];

        }
        return normalAnnotaitonView;
    }
    
    
}
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
    BMKPointAnnotation *anotion = (BMKPointAnnotation *)view.annotation;

    [self saparateAnnotationWithAnnotation:anotion];
}
/**
 *当点击annotation view弹出的泡泡时，调用此接口
 *@param mapView 地图View
 *@param view 泡泡所属的annotation view
 */
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view {
    if ([view.annotation.title isEqualToString:@"媒印象给您红包了，点我领取"]) {//官方红包券
        [self requestOfficialVocher];
        return;
    }
    if ([view.annotation.title isEqualToString:@"点我领红包抵用券"]) {//官方红包券
       // view.annotation;
        VocherAnnotation *vocherAno = (VocherAnnotation *)view.annotation;
        [self requestVocherListWithAnnotaion:vocherAno];
        return;
    }
    if ([view isKindOfClass:[ClusterAnotionView class]]) {
        ClusterAnotion *clusterAnnotation = (ClusterAnotion*)view.annotation;
        if (clusterAnnotation.size > 1) {
            [mapView setCenterCoordinate:view.annotation.coordinate];
            [mapView zoomIn];
        }
    }else{
        [openLuckyView addLuckyMoneyAnnamation];

    }
}
/**
 *地图渲染每一帧画面过程中，以及每次需要重绘地图时（例如添加覆盖物）都会调用此接口
 *@param mapView 地图View
 *@param status 此时地图的状态
 */
- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus *)status {
      //  [self addLockedMapAnnotation];
   
}
- (BMKOverlayView*)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay{
    if ([overlay isKindOfClass:[BMKCircle class]])
    {
        BMKCircleView* circleView = [[BMKCircleView alloc] initWithOverlay:overlay];
        circleView.fillColor = [[UIColor alloc] initWithRed:1 green:0 blue:0 alpha:0.22];
        circleView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.5];
        circleView.lineWidth = 0.0;
        
        return circleView;
    }
    return nil;
}
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    [self addLockedMapAnnotation];
}
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView{
    [self addLockedMapAnnotation];
}
#pragma mark -BaiduLocationServiceMethod
- (void)startLocation{
    [_locationService startUserLocationService];
    _mapView.showsUserLocation = NO;// 关闭图层
    _mapView.userTrackingMode = BMKUserTrackingModeFollow;//定位跟随模式
    _mapView.showsUserLocation = YES;//开启图层
    //设置经纬度范围
    BMKCoordinateSpan span = BMKCoordinateSpanMake(0.01,0.01);
    BMKCoordinateRegion region = BMKCoordinateRegionMake(coor, span);
    [_mapView setRegion:region animated:YES];
    [self addLockedMapAnnotation];
}

/**
 *在地图View将要启动定位时，会调用此函数
 *@param mapView 地图View
 */
- (void)willStartLocatingUser
{
    NSLog(@"start locate");
}

/**
 *用户方向更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    //[_mapView updateLocationData:userLocation];
    NSLog(@"heading is %@",userLocation.heading);
}

/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
        NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    ApplicationDelegate.locationcoor = userLocation.location.coordinate;

    [_mapView removeOverlay:circle];
    circle = nil;
    if (circle == nil) {
        circle = [BMKCircle circleWithCenterCoordinate:userLocation.location.coordinate radius:400];
    }
    [_mapView addOverlay:circle];
    [_mapView updateLocationData:userLocation];
}

/**
 *在地图View停止定位后，会调用此函数
 *@param mapView 地图View
 */
- (void)didStopLocatingUser
{
    NSLog(@"stop locate");
}

/**
 *定位失败后，会调用此函数
 *@param mapView 地图View
 *@param error 错误号，参考CLError.h中定义的错误号
 */
- (void)didFailToLocateUserWithError:(NSError *)error
{
    NSLog(@"location error");
}
#pragma mark -BMKLocationManagerDelegate
-(void)initLocation
{
    _locationManager = [[BMKLocationManager alloc] init];
    
    _locationManager.delegate = self;
    
    _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
    _locationManager.distanceFilter = kCLDistanceFilterNone;
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    _locationManager.activityType = CLActivityTypeAutomotiveNavigation;
    _locationManager.pausesLocationUpdatesAutomatically = NO;
    _locationManager.allowsBackgroundLocationUpdates = YES;
    _locationManager.locationTimeout = 10;
    _locationManager.reGeocodeTimeout = 10;
    _locationManager.distanceFilter = 10;
    [_locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
        if (error == nil) {
            ApplicationDelegate.mCityName = location.rgcData.city;
        }
    }];
}

-(void)initBlock
{
    WS(weakSelf);
    self.completionBlock = ^(BMKLocation *location, BMKLocationNetworkState state, NSError *error)
    {
        if (error)
        {
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            
            
        }
        
        if (location.location) {//得到定位信息，添加annotation
            
            NSLog(@"LOC = %@",location.location);
            BMKPointAnnotation *pointAnnotation = [[BMKPointAnnotation alloc]init];
            
            pointAnnotation.coordinate = location.location.coordinate;
            pointAnnotation.title = @"单次定位";
            if (location.rgcData) {
                pointAnnotation.subtitle = [location.rgcData description];
            } else {
                pointAnnotation.subtitle = @"rgc = null!";
            }
            
            MediaImpressViewController *strongSelf = weakSelf;
            
//            [strongSelf updateMessage:[NSString stringWithFormat:@"当前位置信息： \n经纬度：%.6f,%.6f \n地址信息：%@ \n网络状态：%d",location.location.coordinate.latitude, location.location.coordinate.longitude, [location.rgcData description], state]];
            
            //[_mapView a];
            MyLocation * loc = [[MyLocation alloc]initWithLocation:location.location withHeading:nil];
            [strongSelf addLocToMapView:loc];
            
        }
        
        if (location.rgcData) {
            NSLog(@"rgc = %@",[location.rgcData description]);
        }
        
        NSLog(@"netstate = %d",state);
    };
    
    
}
- (void)addLocToMapView:(MyLocation *)loc
{
    [_mapView updateLocationData:loc];
    [_mapView setCenterCoordinate:loc.location.coordinate animated:YES];
}

- (void)addAnnotationToMapView:(BMKPointAnnotation *)annotation
{
    [_mapView addAnnotation:annotation];
}
#pragma mark - PrivateMethod
//百度地图配置
- (void)configBaiduMap{
    [self configMapView];
    [self startLocation];
    [self initLocation];
    [self initBlock];
}
- (void)createUI{
    //添加定位和客服按钮
    [self addBtns];
    //添加tabbaritembutton
    [self addNavButtons];
}
- (void)configMapView{
    _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight- SafeAreaTopHeight - SafeAreaBottomHeight - TABBARHEIGHT)];
    BMKLocationViewDisplayParam *displayParam = [[BMKLocationViewDisplayParam alloc]init];
    displayParam.isRotateAngleValid = true;//跟随态旋转角度是否生效
    displayParam.isAccuracyCircleShow = NO;//精度圈是否显示
    displayParam.locationViewOffsetX = 0;//定位偏移量(经度)
    displayParam.locationViewOffsetY = 0;//定位偏移量（纬度）
    [_mapView updateLocationViewWithParam:displayParam];
    [_mapView setMapType:BMKMapTypeStandard];
    _locationService = [[BMKLocationService alloc] init];
    [self.view addSubview: _mapView];

}
- (void)addNavButtons{
    UIButton *sharedButton = [UIButton cz_imageButton:@"media_share" backgroundImageName:@"media_share"];
    [sharedButton sizeToFit];
    [sharedButton addTarget:self action:@selector(shared:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:sharedButton];
    UIButton *lessonButton = [UIButton cz_textButton:@"帮助" fontSize:16 normalColor:[UIColor whiteColor] highlightedColor:[UIColor whiteColor]];
    [lessonButton sizeToFit];
    [lessonButton addTarget:self action:@selector(lessonAct) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:lessonButton];
}
- (void)lessonAct{
    MYXCusGuideController *myxguideVC = [MYXCusGuideController loadMYXGusVC];
    myxguideVC.imgurl = @"lessonPic";
    myxguideVC.title = @"帮助";
    [myxguideVC addGuideImg];
    [self.navigationController pushViewController:myxguideVC animated:YES];
}
- (void)shared:(id)sender{
//    [[CHSocialServiceCenter shareInstance] shareTitle:@"媒印象邀您注册享百万年薪" content:@"大家好，我是媒印象cfo lucky liu" imageURL:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1512105433763&di=dd63458f5da2dd4810bb143aea84ab67&imgtype=0&src=http%3A%2F%2Fimg1.3lian.com%2F2015%2Fa1%2F105%2Fd%2F40.jpg" image:[UIImage imageNamed:@"AppIcon"] urlResource:[NSString stringWithFormat:@"http://meiyinxiang.net/"] type:CHSocialQQ controller:self completion:^(BOOL successful) {
//
//    }];
//    [[CHSocialServiceCenter shareInstance] shareTitle:@"媒印象邀您注册享百万年薪"  content:@"大家好，我是媒印象cfo lucky liu" imageURL:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1512105433763&di=dd63458f5da2dd4810bb143aea84ab67&imgtype=0&src=http%3A%2F%2Fimg1.3lian.com%2F2015%2Fa1%2F105%2Fd%2F40.jpg" image:[UIImage imageNamed:@"AppIcon"] urlResource:@"http://meiyinxiang.net/" controller:self completion:^(BOOL successful) {
//
//    }];
    ShareUrlModel *shareModel = [[ShareUrlModel alloc] init];
    shareModel.text = @"媒印象喊您来捡钱了";
    shareModel.imgUrl = @"http://meiyinxiang.net/upload/20171225/8997fba564d8634557ca859e8d935663.jpg";
    shareModel.title = @"媒印象邀您注册抢红包了";
    shareModel.url = @"http://meiyinxiang.net";
    [JpusharedHelper shared].urlModel = shareModel;
    [[JpusharedHelper shared].shareView showWithContentType:3];
  //  NSLog(@"分享");
}
- (void)addNotice{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshLucky) name:RFRESH_LuckyMoneyList object:nil];
}

- (void)addBtns{
    //定位按钮
    if (locationNowBtn == nil) {
        locationNowBtn = [LocationNowBtn loadNibWithLocationBtn];
    }
    [locationNowBtn addTarget:self action:@selector(locationNow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:locationNowBtn];
    [self.view bringSubviewToFront:locationNowBtn];
    [locationNowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-11));
        make.bottom.equalTo(@(-71));
    }];
    //客服按钮
    if (customerSeviceBtn == nil) {
        customerSeviceBtn = [CustomerServiceBtn loadNibWithCustomerServiceBtn];
    }
    [customerSeviceBtn addTarget:self action:@selector(customerService:) forControlEvents:UIControlEventTouchUpInside];
    //[self.view addSubview:customerSeviceBtn];
   // [self.view bringSubviewToFront:customerSeviceBtn];
//    [customerSeviceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(@(-11));
//        make.bottom.equalTo(@(-122));
//    }];
    //刷新红包按钮
    if (refreshBtn == nil) {
        refreshBtn = [RefreshBtn loadNibWithRefreshBtn];
    }
    [refreshBtn addRefreshTarget:self action:@selector(refreshLucky) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:refreshBtn];
    [self.view bringSubviewToFront:refreshBtn];
    [refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-11));
        make.bottom.equalTo(@(-173));
    }];
    //用户指南按钮
    if (questionBtn == nil) {
        questionBtn = [QuestionBtn loadNibWithQuestionBtn];
    }
    [questionBtn addTarget:self action:@selector(question) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:questionBtn];
    [self.view bringSubviewToFront:questionBtn];
    [questionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-11));
        make.bottom.equalTo(@(-122));
    }];
    //添加通知view
    if (noticeView == nil) {
        noticeView = [NoticeView loadNibWithNoticeView];
    }
    [noticeView addTarget:self action:@selector(meiyinxiangNotice:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:noticeView];
    [self.view bringSubviewToFront:noticeView];
    __weak typeof(self) weakself = self;
    [noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakself.view);
        make.right.equalTo(@(-11));
        make.top.equalTo(@(10));
    }];
   // noticeView.noticeString = [MYXMemberMdel sharedInstance].notices;
   // [ noticeView rollAnimation];

}
- (void)saparateAnnotationWithAnnotation:(BMKPointAnnotation * )anotion{
    
    if ([anotion.title isEqualToString:@"我的位置"]) {
        return;
    }
    if ([anotion.title isEqualToString:@"媒印象给您红包了，点我领取"]) {//官方红包。媒印象给你送红包了
        [self requestOfficialVocher];
        return;
    }
    if ([anotion.title isEqualToString:@"点我领红包抵用券"]) {
        VocherAnnotation *vocherAno = (VocherAnnotation *)anotion;
        [self requestVocherListWithAnnotaion:vocherAno];
        
        return;
    }
    if (openLuckyView == nil) {
        openLuckyView = [MYXOpenLuckyMoneyView loadNibMYXLuckyMoneyView]; 
        [self.view addSubview:openLuckyView];
        [self.view bringSubviewToFront:openLuckyView];
        openLuckyView.hidden = YES;
    }
    if ([anotion isKindOfClass:[ClusterAnotion class]]) {
        ClusterAnotion *clusterAnotion = (ClusterAnotion *)anotion;
        openLuckyView.model = clusterAnotion.model;
        openLuckyView.mSuperView = _mapView;
        openLuckyView.mViewController = self;
        [openLuckyView addLuckyMoneyAnnamation];
    }
 
}
- (void)meiyinxiangNotice:(id)sender{
//    [noticeView rollAnimation];
    NSLog(@"点击通知");
}
- (void)customerService:(id)sender{
    NSLog(@"进入客服界面");
}
- (void)refreshLucky{
        dispatch_async(dispatch_get_main_queue(), ^{
            [refreshBtn addRefreshAnimation];
            [self addLockedMapAnnotation];
        });
        
    NSLog(@"刷新红包");
}
- (void)question{
    NSLog(@"添加用户指南");
    MYXCusGuideController *myxguideVC = [MYXCusGuideController loadMYXGusVC];
    myxguideVC.imgurl = @"yhzhinan";
    myxguideVC.title = @"用户指南";
    [myxguideVC addGuideImg];
    [self.navigationController pushViewController:myxguideVC animated:YES];
}
- (void)locationNow:(id)sender{
    //设置经纬度范围
    BMKCoordinateSpan span = BMKCoordinateSpanMake(0.01,0.01);
    BMKCoordinateRegion region = BMKCoordinateRegionMake(coor, span);
[_mapView setRegion:region animated:YES];
[_locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:self.completionBlock];
}
- (void)requestVocherListWithAnnotaion:(VocherAnnotation *)vocherAno{
    [vocherAno.model getVocherWithResult:^(BOOL isSucess, NSString *msg) {
        if (isSucess) {
            MYXHpVocherView *vocherView = [MYXHpVocherView loadNibWithVocherView];
            vocherView.viewModel = vocherAno.model;
            vocherView.mSuperVC = self;
            vocherView.tapBlock = ^(){
                [[KGModal sharedInstance] hide];
            };
            [KGModal sharedInstance].closeButtonType = KGModalCloseButtonTypeNone;
            // [KGModal sharedInstance].tapOutsideToDismiss = NO;
            [KGModal sharedInstance].modalBackgroundColor = [UIColor whiteColor];
            [[KGModal sharedInstance] showWithContentView:vocherView];
        }
    }];
}
- (void)requestOfficialVocher{
    WS(weakSelf);
    [self.moneyViewModel getFirstTicketWithResult:^(BOOL success, NSString *message) {
        if (success) {
            MYXMemberMdel *model = [MYXMemberMdel sharedInstance];
            model.userinfo.is_first = @"1";
            [model save];
            weakSelf.moneyViewModel.isReceivedVocher = YES;
            MYXHpVocherView *vocherView = [MYXHpVocherView loadNibWithVocherView];
            vocherView.mSuperVC = self;
            vocherView.tapBlock = ^(){
                [[KGModal sharedInstance] hide];
            };
            [KGModal sharedInstance].closeButtonType = KGModalCloseButtonTypeNone;
            [KGModal sharedInstance].modalBackgroundColor = [UIColor whiteColor];
            [[KGModal sharedInstance] showWithContentView:vocherView];
        }else{
            [SVProgressHUD showSuccessWithStatus:message];
        }
        
    }];
}
- (void)dealloc{
    if (_mapView) {
        _mapView = nil;
    }
    _locationManager = nil;
    _completionBlock = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:RFRESH_LuckyMoneyList object:nil];
}
#pragma mark -setMethod
//官方红包券图标
- (BMKPointAnnotation *)officailVocher{
    if (_officailVocher == nil) {
        _officailVocher = [[BMKPointAnnotation alloc] init];
    }
    _officailVocher.coordinate = ApplicationDelegate.locationcoor;
    return _officailVocher;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
